% this m file calls the function "convertADVlog_profile2MAT" which will take the Sontek ADV log files in 
%the filename below and removes the sections of the data, saves the profile
%and the indexes for the profile and sample depths
% and the function "getaverageADV" which will get the average data
%from TSS depths, the start and stop times and the number of records
%averaged

%replace the files in "filename" to reflect the ones you want to group together

%NOTE:  Be sure to choose profile first and depth indexes from top to
%bottom

clear all

cruise='YR141204';
folder='/Users/kelsey/Desktop/Dissertation/Profiler Surveys/York River/Anchor Stations/Claybank/YR141204/Sontek B336/';

filename=cellstr([
'A5481'
'A5482'
'A5483'
'A5484'
'A5485'
'A5486'
'A5487'
'A5488'
'A5489'
'A5490'
'A5491']);

distance=[30
30
30
30
30
30
30
30
30
30 
30];

backConc=str2double(inputdlg('Define background concentration in mg/L (typically use minimum concentration of filter TSS samples)','!!USER INPUT REQUIRED!!',1));
%19

b=[-0.877 0.0337];    % For Sontek curve ADV backscatter to TSS calibration using all 2007 + 2008 survey data - set to 0 if no calibration available
%b=[-2.273 0.0447];    % ADV backscatter using Nortek curve (KAF March 2014)

for ii=1:length(filename)
convertADVlog_profile2MAT_Sontek(char(filename(ii)))
%getBackscatterAvgSD_SE (char(filename(ii))) %This processing is now done in getAverageADV_cov_using_backConc.m
getAverageADV_cov_using_backConc(char(filename(ii)),backConc,b)
end

Sdata=create_data_struct_csv_profiler_Sontek(cruise,folder,distance,filename, backConc);    
save(fullfile(folder,[cruise '_SONTEK']),'-struct','Sdata'); 

